home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sun Solutions 1997 April to September
/
Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso
/
products
/
bin
/
httpd
/
Solaris_2
/
http-query-setup.tcl
< prev
next >
Wrap
Text File
|
1995-12-04
|
3KB
|
158 lines
#arguments are passed on command line. '&' separates assignments
#assignments have the form name=value
#'+'s are spaces and spaces separating words on command line are
#actually part of the word
#In our environment, if argument starts with /, then pathname
#components are assignments
# global variable artype(i) defines what type ar(i) should be. Currently,
# list or not.
proc subhex {v} {
# multiline crap I need to parse
# ONE%0D%0ATWO%0D%0ATHREE%0D%0A
set nv $v
regsub -all {%0D%0A} $v "\n" v
while {[regexp {%[0-9A-F][0-9A-F]} $v blah]} {
scan $blah "%%%x" cv
if {[ctype char $cv]=="&"} {
regsub -all $blah $v \\& nv
} else {
regsub -all $blah $v [ctype char $cv] nv
}
set v $nv
}
return $v
}
proc http_proc_args {arg} {
global ar artype
upvar $arg argv
set bigarg ""
#join words with +'s
if [llength $argv]==2 {
set bigarg [split [lindex $argv 1] &]
set path [lindex $argv 0]
set args [split [crange $path 1 end] /]
} else {
set a0 [lindex $argv 0]
if {[lindex $a0 0]=="/"} {
set bigarg {}
set args [split [lrange $a0 1 end] /]
} else {
set bigarg [split $a0 &]
set args {}
}
}
foreach arg [concat $bigarg $args] {
if [regexp {(.*)=(.*)} $arg foo name value] {
set name [subhex $name]
if ![info exists argcount($name)] {
set argcount($name) 1
} else {
incr argcount($name)
}
}
}
#split assignments on the '&'
foreach arg [concat $bigarg $args] {
if [regexp {(.*)=(.*)} $arg foo name value] {
regsub -all {\+} $value { } newval
set name [subhex $name]
set val [subhex $newval]
if ![info exists ar($name)] {
if [info exists artype($name)] {
if {$artype($name)=="list"} {
if {$val!=""} {
set ar($name) [list $val]
} else {
set ar($name) {}
}
} else {
set ar($name) $val
}
} else {
set ar($name) $val
}
} else {
# multiple selection
lappend ar($name) $val
}
}
}
}
#makes URL extended pathname to encode current state
proc pkg_attrs {var attrs} {
upvar $var ar
set al ""
foreach i $attrs {
if [info exists ar($i)] {
# regsub { } $ar($i) {+} att
set al "$al/$i=$att"
}
}
return $al
}
proc http_proc_cgi_args {} {
global ar artype
global env
set bigarg ""
#join words with +'s
if [info exists env(PATH_INFO)] {
set args [split [crange $env(PATH_INFO) 1 end] /]
} else {
set args {}
}
if [info exists env(QUERY_STRING)] {
set bigarg [split $env(QUERY_STRING) &]
} else {
set bigarg {}
}
foreach arg [concat $bigarg $args] {
if [regexp {(.*)=(.*)} $arg foo name value] {
set name [subhex $name]
if ![info exists argcount($name)] {
set argcount($name) 1
} else {
incr argcount($name)
}
}
}
#split assignments on the '&'
foreach arg [concat $bigarg $args] {
if [regexp {(.*)=(.*)} $arg foo name value] {
regsub -all {\+} $value { } newval
set name [subhex $name]
set val [subhex $newval]
if ![info exists ar($name)] {
if [info exists artype($name)] {
if {$artype($name)=="list"} {
if {$val!=""} {
set ar($name) [list $val]
} else {
set ar($name) {}
}
} else {
set ar($name) $val
}
} else {
set ar($name) $val
}
} else {
# multiple selection
lappend ar($name) $val
}
}
}
}